package com.fenghongzhang.day013.mvp.view.fragment;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.fenghongzhang.day013.R;
import com.fenghongzhang.day013.adapter.MeiziAdapter;
import com.fenghongzhang.day013.entity.Meizi;
import com.fenghongzhang.day013.mvp.contract.MeiziContract;
import com.fenghongzhang.day013.mvp.model.MeiziModel;
import com.fenghongzhang.day013.mvp.presenter.MeiziPresenter;
import com.fenghongzhang.lib.mvp.view.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MeiziFragment extends BaseFragment<MeiziPresenter> implements MeiziContract.IMeiziView {

    private RecyclerView rv;

    private List<Meizi.DataBean> list1;

    @Override
    public void showMeizi(List<Meizi.DataBean> list) {
        list1.addAll(list);
        MeiziAdapter meiziAdapter = new MeiziAdapter(R.layout.rv_layout,list1);
        rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        rv.setAdapter(meiziAdapter);
    }


    @Override
    public int bindLayout() {
        return R.layout.fragment_meizi;
    }

    @Override
    public void initView() {
        rv = (RecyclerView) findViewById(R.id.rv);
        list1 = new ArrayList<>();
    }

    @Override
    public void initData() {
        mPresenter = new MeiziPresenter(new MeiziModel(),this);
        mPresenter.getMeizi();
    }


    @Override
    public void showToast(String s) {

    }
}
